package com.dropdb.demo.service.impl;

import com.dropdb.demo.bean.Log;
import com.dropdb.demo.bean.LogExample;
import com.dropdb.demo.bean.bo.AdminLogListBO;
import com.dropdb.demo.bean.bo.BaseData;
import com.dropdb.demo.mapper.LogMapper;
import com.dropdb.demo.service.LogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogServiceImpl implements LogService {

    @Autowired
    LogMapper logMapper;

    @Override
    public BaseData<Log> list(AdminLogListBO bo) {
        LogExample logExample = new LogExample();
        LogExample.Criteria criteria = logExample.createCriteria();
        if (null != bo.getName()) {
            criteria.andAdminEqualTo(bo.getName());
        }
        criteria.andDeletedEqualTo(false);
        logExample.setOrderByClause(bo.getSort() + " " + bo.getOrder());
        PageHelper.startPage(bo.getPage(), bo.getLimit());
        List<Log> logs = logMapper.selectByExample(logExample);
        PageInfo<Log> pageInfo = new PageInfo<>(logs);
        long total = pageInfo.getTotal();
        return new BaseData<>(total, logs);
    }
}
